package datafeed

import (
	"context"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"kubequant/conf"
)

func NewMongoDataFeed() *MongoDataFeed {
	mongoDataFeed := new(MongoDataFeed)
	return mongoDataFeed
}

type MongoDataFeed struct {
	Client     *mongo.Client
	DB         *mongo.Database
	Collection *mongo.Collection
}

// Init 初始化mongodb
func (mongoDataFeed MongoDataFeed) Init() error {
	setting := conf.LoadSetting()
	option := options.Client().ApplyURI(setting.DataFeed.Url)
	client, err := mongo.Connect(context.TODO(), option)

	if err != nil {
		return err
	}
	//检查连接
	err = client.Ping(context.TODO(), nil)
	if err != nil {
		return err
	}
	mongoDataFeed.DB = client.Database(setting.DataFeed.DB)
	mongoDataFeed.Collection = mongoDataFeed.DB.Collection(setting.DataFeed.Collection)
	mongoDataFeed.Client = client
	return nil
}

func (mongoDataFeed MongoDataFeed) QueryBarHistory() {

}

func (mongoDataFeed MongoDataFeed) QueryTickHistory() {

}
